package cn.ecut.Servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.ecut.Dao.ApplyDao;
import cn.ecut.Bean.Apply;

@WebServlet("/ApprovalServlet")
public class ApprovalServlet extends HttpServlet {


    public ApprovalServlet() {
        super();
    }

    public void destroy() {
        super.destroy();
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        this.doPost(request, response);
    }


    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");    //设置请求数据的字符编码格式
        String condition = request.getParameter("Condition"); //获得请求表单中的状态情况
        Apply apply = new Apply();
        apply.setCondition(condition);
        ApplyDao ud = new ApplyDao();
        if(ud.approval(apply)){
            request.getRequestDispatcher("index.jsp").forward(request, response);//状态修改成功显示的窗口
        }
        else {
            response.sendRedirect("index2.jsp");//状态修改失败显示的窗口
        }
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
        // Put your code here
    }
}